
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:SetPlayer(ply)
	self:SetPhysicsAttacker(ply)
	self:SetOwner(ply)
end

function ENT:Initialize()

	self:SetModel( "models/props_junk/propane_tank001a.mdl" )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS ) 
	
	local phys = self:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableDrag(true)
		phys:EnableCollisions(true)
	end
end

function ENT:LockTarget()
	local pos = self:GetPos()
	local ang = self:GetAngles()
	local tracedata = {}
	tracedata.start = pos + self:GetTrueForward()*50
	tracedata.endpos = pos + self:GetTrueForward()*90000
	local trace = util.TraceLine(tracedata)
	if trace.Entity then
		return trace.Entity
	else
		return nil
	end
end

function ENT:GetTrueUp()
	return self:GetUp()
end

function ENT:GetTrueForward()
	return self:GetForward()
end

function ENT:GetTrueRight()
	return self:GetRight()
end

function ENT:ExplosionDamage(owner,pos,damage,radius,physforce,sound,pitch)

	util.BlastDamage( owner, owner, pos, radius, damage )
	util.ScreenShake( pos, math.Rand(2,5),220, math.random(2,4), radius + 100 ) 
	if sound then
		self:EmitSound(sound,100,pitch)
	end

	local tracedata = {}
	tracedata.start = pos
	tracedata.endpos = pos+Vector(math.random(-10,10),math.random(-10,10),-250)
	tracedata.filter = self
	local trace = util.TraceLine(tracedata)
	if trace.HitWorld then
		util.Decal("FadingScorch",trace.HitPos+trace.HitNormal,trace.HitPos-trace.HitNormal)
		local effectdata = EffectData()
		effectdata:SetOrigin(trace.HitPos)
		util.Effect("smoke_crater_small", effectdata)
	end
	
	for k,v in pairs(ents.FindInSphere(pos,radius)) do
		v:Extinguish()
		if physforce then
			local phys = v:GetPhysicsObject()
			if phys and phys:IsValid() then
				local force = (v:GetPos() - self:GetPos()):Normalize()
				phys:ApplyForceCenter(force * physforce)
			end
		end
	end
end

function ENT:Think()
  
end 
 
function ENT:OnTakeDamage( dmginfo )
	
	self.Entity:TakePhysicsDamage( dmginfo )

end

function ENT:PhysicsSimulate(phys, frametime)

	phys:Wake()
	phys:EnableGravity(false)
	
end

function ENT:PhysicsCollide( data, phys )

	phys:Wake()
	
end